<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>馆藏图书</title>
    <!--  引入核心皮肤-->
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <!--   引入核心js-->
    <script src="../../layui/layui.js"></script>
    <script>
        layui.use(['layer', 'jquery', 'table', 'form', 'laydate'], function () {
            let layer = layui.layer;//定义组件
            let $ = layui.jquery;//定义组件
            let table = layui.table;//定义表格组件
            let form = layui.form;//定义表格组件
            let laydate = layui.laydate;
            //日期

            layer.open({
                title:"请填写新建试卷相关信息",
                type: 2,
                closeBtn: 0,
                area: ['800px', '600px'],
                content: 'question.html',
                btn: ['确定', '取消'],
                yes: function (index, layero) {
                    var data = $(layero).find('iframe')[0].contentWindow.callbackdata();
                    form.val('form', {
                        interest1: data.interest1,

                    })
                    form.render();
                    form.val('zj-form', {
                        interest: data.interest2,
                    })
                    form.render();
                    $.ajax({
                        type: "post",
                        url: "../../question/insertOne",
                        data: {
                            "questionname": data.questionname,
                            "startdate":data.date1,
                            "enddate": data.date2,
                        },
                        success: function (data) {
                            layer.msg('添加成功了哦！');
                            form.val('form', {
                                questionname: data.questionname,
                                questionid: data.questionid,
                                paperid: data.questionid
                            })
                            form.render();
                        }

                    });

                    layer.close(index);
                }
                , btn2: function (index, layero) {
                    layer.close(index)
                    return false
                }
                , cancel: function (index, layero) {
                    layer.close(index)
                    return false
                }
            });
            form.on('select(Rolloutmode)', function (data) {
                if (data.value == '0') {

                    form.on('select(selectedtopic)', function (data) {
                        if (data.value != '') {
                            layer.msg('请选择出卷方式为选题出卷', {icon: 5});

                        }
                    })
                    layer.open({
                        type: 1,
                        closeBtn: 0,
                        area: ['600px', '300px'],
                        content: '确定系统随机抽题吗',
                        btn: ['确定', '取消'],

                        yes: function (index) {
                            $.ajax({
                                type: "post",
                                url: "../../roa/random",
                                data: {"questionid": $("#questionid").val()},
                                success: function (data) {
                                    layer.msg('系统随机抽题成功！');
                                    console.log(data);
                                }
                            });
                            layer.close(index);
                        }
                        , btn2: function (index) {
                            layer.close(index)
                            return false
                        }
                        , cancel: function (index) {
                            layer.close(index)
                            return false
                        }
                    });


                } else if (data.value == '1') {
                    form.on('select(selectedtopic)', function (data) {
                        if (data.value == '0') {
                            layer.open({
                                type: 2,
                                closeBtn: 0,
                                area: ['800px', '600px'],
                                content: 'Fillbacks.html',
                                btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    var body = layer.getChildFrame('body', index);
                                    var iframeWin = window[layero.find('iframe')[0]['name']];
                                    var checkStatus = iframeWin.layui.table.checkStatus('dg');
                                    if (checkStatus.data.length > 0) {
                                        // var data1 = {
                                        //     lists: checkStatus.data,
                                        //     questionid:$("#questionid").val(),
                                        // }
                                        // console.log(data1);

                                        let qnos = [];
                                        for (let i in checkStatus.data) {
                                            qnos.push(checkStatus.data[i].qno)
                                        }
                                        $.post('../../roa/chooseFillbacks', {
                                            "lists[]": qnos,
                                            questionid: $("#questionid").val()
                                        }, function (flag) {
                                            if (flag) {
                                                layer.msg('添加填空题成功', {icon: 6});
                                                table.reload("dg");//刷新表格
                                                layer.closeAll('page');//关闭当前对话框
                                            } else {
                                                layer.msg('添加填空题失败', {icon: 5});
                                            }
                                        })
                                    }
                                    layer.close(index);
                                }

                                , btn2: function (index, layero) {
                                    layer.close(index)
                                    return false
                                }
                                , cancel: function (index, layero) {
                                    layer.close(index)
                                    return false
                                }
                            })
                        } else if (data.value == '2') {
                            layer.open({
                                type: 2,
                                closeBtn: 0,
                                area: ['800px', '600px'],
                                content: 'torf.html',
                                btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    var body = layer.getChildFrame('body', index);
                                    var iframeWin = window[layero.find('iframe')[0]['name']];
                                    var checkStatus = iframeWin.layui.table.checkStatus('dg');
                                    if (checkStatus.data.length > 0) {
                                        // var data1 = {
                                        //     lists: checkStatus.data,
                                        //     questionid:$("#questionid").val(),
                                        // }
                                        // console.log(data1);
                                        let qnos = [];
                                        for (let i in checkStatus.data) {
                                            qnos.push(checkStatus.data[i].qno)
                                        }
                                        $.post('../../roa/chooseTorf', {
                                            "lists[]": qnos,
                                            questionid: $("#questionid").val()
                                        }, function (flag) {
                                            if (flag) {
                                                layer.msg('添加判断题成功', {icon: 6});
                                                table.reload("dg");//刷新表格
                                                layer.closeAll('page');//关闭当前对话框
                                            } else {
                                                layer.msg('添加判断题失败', {icon: 5});
                                            }
                                        })
                                    }
                                    layer.close(index);
                                }

                                , btn2: function (index, layero) {
                                    layer.close(index)
                                    return false
                                }
                                , cancel: function (index, layero) {
                                    layer.close(index)
                                    return false
                                }
                            })
                        } else if (data.value == '3') {
                            layer.open({
                                type: 2,
                                closeBtn: 0,
                                area: ['800px', '600px'],
                                content: 'Subjective.html',
                                btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    var body = layer.getChildFrame('body', index);
                                    var iframeWin = window[layero.find('iframe')[0]['name']];
                                    var checkStatus = iframeWin.layui.table.checkStatus('dg');
                                    if (checkStatus.data.length > 0) {
                                        // var data1 = {
                                        //     lists: checkStatus.data,
                                        //     questionid:$("#questionid").val(),
                                        // }
                                        // console.log(data1);

                                        let qnos = [];
                                        for (let i in checkStatus.data) {
                                            qnos.push(checkStatus.data[i].subid)
                                        }
                                        $.post('../../roa/chooseSubjective', {
                                            "lists[]": qnos,
                                            questionid: $("#questionid").val()
                                        }, function (flag) {
                                            if (flag) {
                                                layer.msg('添加主观题成功', {icon: 6});
                                                table.reload("dg");//刷新表格
                                                layer.closeAll('page');//关闭当前对话框
                                            } else {
                                                layer.msg('添加主观题失败', {icon: 5});
                                            }
                                        })
                                    }
                                    layer.close(index);
                                }

                                , btn2: function (index, layero) {
                                    layer.close(index)
                                    return false
                                }
                                , cancel: function (index, layero) {
                                    layer.close(index)
                                    return false
                                }
                            })
                        } else if (data.value == '1') {
                            layer.open({
                                type: 2,
                                closeBtn: 0,
                                area: ['800px', '600px'],
                                content: 'Choice.html',
                                btn: ['确定', '取消']
                                , yes: function (index, layero) {
                                    var body = layer.getChildFrame('body', index);
                                    var iframeWin = window[layero.find('iframe')[0]['name']];
                                    var checkStatus = iframeWin.layui.table.checkStatus('dg');
                                    if (checkStatus.data.length > 0) {
                                        // var data1 = {
                                        //     lists: checkStatus.data,
                                        //     questionid:$("#questionid").val(),
                                        // }
                                        // console.log(data1);

                                        let qnos = [];
                                        for (let i in checkStatus.data) {
                                            qnos.push(checkStatus.data[i].chid)
                                        }
                                        $.post('../../roa/chooseChoice', {
                                            "lists[]": qnos,
                                            questionid: $("#questionid").val()
                                        }, function (flag) {
                                            if (flag) {
                                                layer.msg('添加选择题成功', {icon: 6});
                                                table.reload("dg");//刷新表格
                                                layer.closeAll('page');//关闭当前对话框
                                            } else {
                                                layer.msg('添加选择题失败', {icon: 5});
                                            }
                                        })
                                    }
                                    layer.close(index);
                                }

                                , btn2: function (index, layero) {
                                    layer.close(index)
                                    return false
                                }
                                , cancel: function (index, layero) {
                                    layer.close(index)
                                    return false
                                }
                            })
                        }
                    })
                }


            })

            $("#btn-yl").click(function () {
                layer.open({
                    title: '预览试卷',
                    type: 2,
                    content: "myquestion.html",
                    area: ['1000px','1000px']
                })

            })
            $("#btn-fb").click(function () {
                layer.open({
                    title: '发布试卷',
                    type: 1,
                    closeBtn: 0,
                    area: ['600px', '300px'],
                    content: $("#edit-dialog").html(),
                    btn: ['发布该考试', '取消该考试']
                    , btn2: function (index) {
                        layer.close(index)
                        return false
                    }
                    , cancel: function (index) {
                        layer.close(index)
                        return false
                    }
                });
            })
        })

    </script>
    <script id="edit-dialog" type="text/html">
            <div style="position:absolute;left:150px;top:100px">
                <h2>发布考试，可在历史试卷查看</h2>
            </div>
        </form>
    </script>
</head>
<body>
<table id="dg1"></table>
<div class="layui-container">
<!--    <div class="layui-col-md3">-->
        <div class="layui-panel">
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                <legend>试卷信息</legend>
            </fieldset>
            <div class="layui-container">
                <div class="layui-row">
                    <div class="layui-bg-gray" style="padding: 30px 30px;">
                        <form class="layui-form" id="form" lay-filter="form">
                            <div class="layui-form-item">
                                <label class="layui-form-label">试卷名称</label>
                                <div class="layui-input-block">
                                    <input type="text" readonly="true" style="background:#CCCCCC" name="questionname"
                                           class="layui-input">
                                    <input type="hidden" id="questionid" name="questionid" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">试卷分类</label>
                                <div class="layui-input-block">
                                    <select name="interest1" lay-filter="aihao" readonly="true" style="background:#CCCCCC">
                                        <option value=""></option>
                                        <option value="0">语文</option>
                                        <option value="1" selected="">数学</option>
                                    </select>
                                </div>
                            </div>

                        </form>
                    </div>
                </div>




            </div>



            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                <legend>添加试题</legend>
            </fieldset>
            <form class="layui-form" lay-filter="zj-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">组卷方式</label>
                    <div class="layui-input-block">
                        <select name="interest" lay-filter="Rolloutmode">
                            <option value=""></option>
                            <option value="0">随机组卷</option>
                            <option value="1">选题组卷</option>
                        </select>
                    </div>
                </div>
                <!--                <div class="layui-form-item">-->
                <!--                    <label class="layui-form-label">试题总数</label>-->
                <!--                    <input type="text" readonly="true" style="background:#CCCCCC" name="all" lay-verify="title"-->
                <!--                           autocomplete="off" placeholder="试题总数" class="layui-input">-->

                <!--                </div>-->
                <!--                <div class="layui-form-item">-->
                <!--                    <label class="layui-form-label">试题总分</label>-->
                <!--                    <input type="text" readonly="true" style="background:#CCCCCC" name="count" lay-verify="title"-->
                <!--                           autocomplete="off" placeholder="分数" class="layui-input">-->

                <!--                </div>-->
            </form>
            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
                <legend>新的试卷</legend>
            </fieldset>
            <form class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">选择框</label>
                    <div class="layui-input-block">
                        <select name="interest" lay-filter="selectedtopic">
                            <option value=""></option>
                            <option value="0">选择填空题</option>
                            <option value="1">选择选择题</option>
                            <option value="2">选择判断题</option>
                            <option value="3">选择主观题</option>
                        </select>
                    </div>
                </div>
            </form>
            <div class="layui-panel">
                <div style="padding: 30px;">
                    <table id="dg"></table>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal" lay-submit id="btn-yl">试卷预览</button>

                        <button class="layui-btn layui-btn-lg layui-btn-radius layui-btn-warm" lay-submit id="btn-fb">发布试卷</button>
                    </div>
                </div>
            </div>
        </div>

<!--    </div>-->
<!--    <div class="layui-col-md9">&ndash;&gt;-->

<!--    </div>-->
</div>
</body>
</html>